home *** CD-ROM | disk | FTP | other *** search
- unit CreateRem;
-
- interface
- uses ActiveX;
-
- function CreateRemComObject(const MachineName: WideString;
- const ClassID,InterFaceID: TGUID) : IUnknown;
- implementation
-
- uses Windows,Sysutils,ComObj,DCOMSecUtils;
-
- type
- TCoCreateInstanceExProc = function(const clsid: TCLSID;
- unkOuter: IUnknown; dwClsCtx: Longint; ServerInfo: PCoServerInfo;
- dwCount: Longint; rgmqResults: PMultiQIArray): HResult stdcall;
-
- var
- CoCreateInstanceEx: TCoCreateInstanceExProc = nil;
-
-
- function CreateRemComObject(const MachineName: WideString;
- const ClassID,InterFaceID: TGUID) : IUnknown;
- const
- LocalFlags = CLSCTX_LOCAL_SERVER or CLSCTX_REMOTE_SERVER or CLSCTX_INPROC_SERVER;
- RemoteFlags = CLSCTX_REMOTE_SERVER;
- var
- MQI: TMultiQI;
- ServerInfo: TCoServerInfo;
- Flags, Size: DWORD;
- Ole32: HModule;
- LocalMachine: array [0..MAX_COMPUTERNAME_LENGTH] of char;
- CoAuthInfo : TCoAuthInfo;
- COAUTHID : TCOAUTHIDENTITY;
- begin
- if @CoCreateInstanceEx = nil then
- begin
- Ole32 := GetModuleHandle('ole32.dll');
- Win32Check(Ole32 > HINSTANCE_ERROR);
- @CoCreateInstanceEx := GetProcAddress(Ole32, 'CoCreateInstanceEx');
- if @CoCreateInstanceEx = nil then
- raise Exception.Create('DCOM is not installed');
- end;
-
- FillChar(ServerInfo, sizeof(ServerInfo), 0);
- ServerInfo.pwszName := PWideChar(MachineName);
- MQI.IID := @InterFaceID;
- MQI.itf := nil;
- MQI.hr := 0;
- { If a MachineName is specified check to see if it the local machine.
- If it isn't, do not allow LocalServers to be used. }
- if Length(MachineName) > 0 then
- begin
- Size := Sizeof(LocalMachine); // Win95 is hypersensitive to size
- if GetComputerName(LocalMachine, Size) and
- (AnsiCompareText(LocalMachine, MachineName) = 0) then
- Flags := LocalFlags else
- Flags := RemoteFlags;
- end else
- Flags := LocalFlags;
- OleCheck(CoCreateInstanceEx(ClassID, nil, Flags, @ServerInfo, 1, @MQI));
- OleCheck(MQI.HR);
- Result := MQI.itf;
- end;
-
- end.
-